const BASE_URL ="https://www.fastmock.site/mock/ec5628405b1c126d42b5e69d44572fd5/api";

const http = {
  get(url, params) {
    // 判断params是否存在
    if (params) {
      let newarr = Object.keys(params).map((el) => {
        return el + "=" + params[el];
      });
      let newstr = newarr.join("&");
      url += "?" + newstr;
    }
    return fetch(BASE_URL + url)
      .then((res) => res.json())
      .then((res) => {
        if (res.status === 0) {
          return res;
        }
      });
  },
  post(url, data) {
    return fetch(BASE_URL + url, {
      method: "POST",
      body: JSON.stringify(data),
      headers: new Headers({
        "Content-Type": "application/json",
      }),
    })
      .then((res) => res.json())
      .then((res) => {
        return res;
      });
  },
};
export default http;
